/*
 * ControlDrawPane.c
 *
 *  Created on: 05.07.2011
 *      Author: sili
 */

#include "ControlDrawPane.h"

static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("at.sili.aalsystem.visualization.ControlDrawPane"));

ControlDrawPane::ControlDrawPane(cPixmap * _pixmap, AALArea * _area, uint32_t _colorBg) : DrawPane(_pixmap, _area, _colorBg, DrawPane::controlPaneType, "controlPane"){
	this->createControlAreas();
}

ControlDrawPane::ControlDrawPane(const int _bpp, AALArea * _area, uint32_t _colorBg) : DrawPane(_bpp, _area, _colorBg, DrawPane::controlPaneType, "controlPane"){
	this->createControlAreas();
}

ControlDrawPane::~ControlDrawPane() {

}

void ControlDrawPane::createControlAreas(){
	// int width = area.width - 2 * area.left;
	// int height = area.height - 2 * area.top;
	AAL_DEBUG(logger, "Control AALArea: left:%f top:%f width:%f heght:%f", area.left, area.top, area.width, area.height);

	int controlElementWidth = area.width / 4.0;
	for(int i=0; i<4; i++){
		//controlElementsArea[i]=AALArea(area.left + i*controlElementWidth, 0, controlElementWidth, area.height);
		controlElementsArea[i].left = area.left + i*controlElementWidth;
		controlElementsArea[i].top = 0;
		controlElementsArea[i].width = controlElementWidth;
		controlElementsArea[i].height = area.height;
		AAL_DEBUG(logger, "Control %i AALArea: left:%f top:%f width:%f heght:%f", i, controlElementsArea[i].left, controlElementsArea[i].top, controlElementsArea[i].width, controlElementsArea[i].height);
	}

}

void ControlDrawPane::drawControl(int _index, string _controlName, tColor _colorFg, tColor _colorBg, const cFont * _font, int _alignment){
	if(_index > (int)(sizeof(this->controlElementsArea) / sizeof(this->controlElementsArea[0]))){
		AAL_ERROR(logger, "Given _index %d out of ControlDrawPane.controlElementsArea array size %d",_index,sizeof(this->controlElementsArea) / sizeof(this->controlElementsArea[0]));
		return;
	}

	int t = int(floor(this->controlElementsArea[_index].top));
	int l = int(floor(this->controlElementsArea[_index].left));
	int w = int(floor(this->controlElementsArea[_index].width));
	int h = int(floor(this->controlElementsArea[_index].height));

	cPoint controlPoint;
	controlPoint.SetY(t);
	controlPoint.SetX(l);
	AAL_DEBUG(logger, "Drawing control text %s at x:%d y:%d w:%d h:%d",(_controlName.size() == 0) ? " ":_controlName.c_str(),
			controlPoint.X(), controlPoint.Y(), w, h);
	this->DrawText(controlPoint, (_controlName.size() == 0) ? " ":_controlName.c_str(), _colorFg, _colorBg, _font, w, h, _alignment);
}
